/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.data.collections.Map;

import fever.app.local.Localisation;
import fever.ioc.plugin.FeverPlugin;

/**
 * {@link fever.ioc.plugin.RegistredPlugin} plugin informations structure.
 * 
 * //TODO Documentation of basic Plugin xml file definition.
 * 
 * @author Romain Ecarnot
 */
class fever.ioc.plugin.PluginInfo
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _mNameMap : Map;
	private var _mDescMap : Map;
	
	private var _sName : String;
	private var _sChannel : String;
	private var _sAuthor : String;
	private var _sVersion : String;	private var _sThumbID : String;
	
	
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
	
	/** Read Only. Returns plugin name. */
	public function get name() : String
	{ 
		if( _mNameMap.containsKey( Localisation.lang ) )
		{
			return _mNameMap.get( Localisation.lang );	
		}
		else return _sName;
	}
	
	/** Read Only. Returns plugin description. */
	public function get description() : String
	{ 
		if( _mDescMap.containsKey( Localisation.lang ) )
		{
			return _mDescMap.get( Localisation.lang );	
		}
		else return ''; 
	}
	
	/** Read Only. Returns plugin channel. */
	public function get channel() : String { return _sChannel; }
	
	/** Read Only. Returns plugin author. */
	public function get author() : String { return _sAuthor; }
	
	/** Read Only. Returns plugin version. */
	public function get version() : String { return _sVersion; }
	
	/** Read Only. Returns plugin thumbail ID. */
	public function get thumbail() : String { return _sThumbID; }
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * @param owner {@link fever.ioc.plugin.FeverPlugin} plugin
	 */ 
	public function PluginInfo( owner : FeverPlugin, vo : Object ) 
	{
		_sChannel = owner.getChannel();
		
		if( vo )
		{
			_mNameMap = _createMap( vo.name );
			_mDescMap = _createMap( vo.description );
			_sAuthor = vo.author || '';
			_sVersion = vo.version || '';
		}
		else 
		{
			_sName = owner.getName();
			_sAuthor = '';
			_sVersion = '';
			_sThumbID = null;
		}	}
	
	/**
	 * Defines thumbail ID in default bitmap data repository.
	 */
	public function setThumbailID( thumbID : String ) : Void
	{
		if( thumbID ) _sThumbID = thumbID;
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return 'Plugin [' + name + '] on Channel [' + channel + ']';
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	private function _createMap( o : Object ) : Map 
	{
		var m : Map = new Map();
		
		for( var s : String in o ) m.put( s, o[s] );
		
		return m;
	}	
}